package com.yuqingsong.freemarker;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class TestMarco {
	
	static public void marcoParam() throws TemplateException, IOException{
		Configuration	cfg = new Configuration();
//		cfg.setSettings(TestMarco.class.getResourceAsStream("scriptsWithMarco"));
	   InputStream in = TestMarco.class.getResourceAsStream("freemarker.prop");
	   Properties p = new Properties();
	   p.load(in);
		
      cfg.setEncoding(Locale.CHINA, "UTF-8");
      Map<String, String> m = new HashMap<String, String>();
      
      String filePath = TestMarco.class.getResource("../freemarker").getFile();
		System.out.println(filePath);
      cfg.setDirectoryForTemplateLoading(new File(filePath));
      cfg.setObjectWrapper(new DefaultObjectWrapper());
      cfg.setSettings(p);
      Template template = cfg.getTemplate("scripts.ftl");
      Writer out = new OutputStreamWriter(System.out);
      template.process(null, out);
      String sql = "create table myTable {id int,name varchar(10)}";
      
     
	}
	
	public static void main(String[] args) throws TemplateException, IOException {
		marcoParam();
	}

}
